import {menuIndexKey, tokenKey} from "@/utils/const-value"

/**
 * window.localStorage 浏览器永久缓存
 */

export const Local = {
    setToken(val: any) {
        this.set(tokenKey,val)
    },
    getToken() {
        let index = this.get(tokenKey)
        return index;
    },
    removeToken(){
        this.remove(tokenKey)
    },
    setMenuIndex(val: any) {
        this.set(menuIndexKey,val)
    },
    getMenuIndex() {
        let index = this.get(menuIndexKey)
        return index;
    },
    // 设置永久缓存
    set(key: string, val: any) {
        window.localStorage.setItem(key, JSON.stringify(val));
    },
    // 获取永久缓存
    get(key: string) {
        let json: any = window.localStorage.getItem(key);
        if (json == "undefined")
            return null;
        return JSON.parse(json);
    },
    // 移除永久缓存
    remove(key: string) {
        window.localStorage.removeItem(key);
    },
    // 移除全部永久缓存
    clear() {
        window.localStorage.clear();
    },
};
